//
//  XYMainViewController.swift
//  01.XinLangWB
//
//  Created by xiaoyudong on 16/4/6.
//  Copyright © 2016年 苏小样. All rights reserved.
//

import UIKit

class XYMainViewController: UITabBarController {
    @objc private func pushBtnDidClick() {
        print("我要撰写被点击事件")
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        //自定义tabBar
        let mainTabBar = XYMainTabBar()
        //添加点击事件
        mainTabBar.pushBtn .addTarget(self, action: "pushBtnDidClick", forControlEvents: .TouchUpInside)
        setValue(mainTabBar, forKey: "tabBar")
        addChildViewControllers()
    }

    //MARK:添加子控制器
    private func addChildViewControllers() {
        addChildViewController(XYHomeTableViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(XYMessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(XYDiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(XYProfileTableViewController(), title: "我", imageName: "tabbar_profile")
 }
//private  只有在 '当前文件内'bv 才可以访问该方法
    private func addChildViewController(vc : UIViewController, title : String, imageName : String ) {
        vc.title = title
        vc.tabBarItem.image = UIImage(named: imageName)
//设置选中的item的模式不然颜色不会变
        vc.tabBarItem.selectedImage = UIImage(named: imageName+"_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        //设置文字的颜色
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: .Selected)
        let nav = XYBaseNavViewController(rootViewController: vc)
        addChildViewController(nav)
        
    }

}

